﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserLogin : System.Web.UI.Page
{
    string roleId = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtSFZH.Text.Trim() != string.Empty && txtName.Text.Trim() != string.Empty)
            {
                string schoolFlag = string.Empty;
                if (User_Control.User_Login(txtSFZH.Text.Trim(), txtName.Text.Trim(),out schoolFlag))
                {
                    Session["userName"] = txtName.Text.Trim();
                    Session["studIdcard"] = txtSFZH.Text.Trim();
                    Session["schoolFlag"] = schoolFlag;
                    DataTable dt = User_Control.getUserInfoByLoginMsg(txtName.Text.Trim(), txtSFZH.Text.Trim());
                    DataTable dt_student = User_Control.getStudInfoByIdCard(txtSFZH.Text.Trim());
                    if (dt.Rows[0]["RoleID"].ToString() == "99")
                    {
                        Response.Redirect(BSUtility.mainUrl + "admin/AdminHomePage.aspx");
                    }
                    else if (dt_student.Rows.Count > 0)
                    {
                        Response.Redirect(BSUtility.mainUrl + "Default.aspx");
                        //if (dt_student.Rows[0]["StudState"].ToString() == "0")
                        //{
                        //    Response.Redirect(BSUtility.mainUrl + "Default.aspx");
                        //}
                        //else
                        //{
                        //    BSUtility.WindowAlert(this, "该账号正在审核中!!");
                        //}                          
                    }
                    else
                    {
                        BSUtility.WindowAlert(this, "账号不存在!");
                    }
                }
                else
                {
                    BSUtility.WindowAlert(this, "帐号或者密码错误!");
                }
            }
            else
            {
                BSUtility.WindowAlert(this, "内容为空");
            }
        }
        catch (TimeoutException ex)
        {
            BSUtility.WindowAlert(this, "登录异常");
        }


    }

}